package com.geologyoa.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSON;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.util.JSONStringer;

import com.geologyoa.commons.JsonTools;
import com.geologyoa.domain.Cjdw01;
import com.geologyoa.domain.Xmqk01;
import com.geologyoa.domain.Xmqk01New;
import com.geologyoa.domain.ZHD01;
import com.geologyoa.domain.Zjpf01;
import com.geologyoa.service.SystemManager;
import com.geologyoa.service.SystemManagerImpl;

public class AddXmqk01ForOneToMany extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public AddXmqk01ForOneToMany() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		doPost(request, response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		//{"zjpf":[{"ZJPF0101":0,"ZJPF0102":0,"ZJPF0103":"资金批复0","ZJPF0104":"","ZJPF0105":0,"ZJPF0106":"","ZJPF0107":""}],"xmqk":{"xmqk01001":1,"xmqk01002":"项目名称1","xmqk01003":"测试json","xmqk01004":"","xmqk01005":"","xmqk01006":"","xmqk01007":"","xmqk01008":"","xmqk01009":"","xmqk01010":"","xmqk01011":"","xmqk01012":"","xmqk01013":"","xmqk01014":"","xmqk01015":"","xmqk01016":"","xmqk01017":0,"xmqk01018":0,"xmqk01019":0,"xmqk01020":0,"xmqk01021":0,"xmqk01022":0,"xmqk01023":0,"xmqk01024":0,"xmqk01025":"","xmqk01026":"","xmqk01027":"","xmqk01028":"","xmqk01029":"","xmqk01030":"","xmqk01031":"","xmqk01032":"","xmqk01033":"","xmqk01034":"","xmqk01035":"","xmqk01036":"","xmqk01037":0,"xmqk01038":"","xmqk01039":"","xmqk01040":"","xmqk01041":"","xmqk01042":"","xmqk01043":0,"xmqk01044":0,"xmqk01045":0,"xmqk01046":0,"xmqk01047":0,"xmqk01048":"","xmqk01049":"","xmqk01050":"","xmqk01051":"","xmqk01052":"","xmqk01053":"","xmqk01054":"","xmqk01055":"","xmqk01056":"","xmqk01057":"","xmqk01058":"","xmqk01059":"","xmqk01060":0,"xmqk01061":"","xmqk01062":"","xmqk01063":"","xmqk01064":"","xmqk01065":"","xmqk01066":"","xmqk01067":"","xmqk01068":"","xmqk01069":"","xmqk01070":"","xmqk01071":"","xmqk01072":"","xmqk01073":0,"xmqk01074":"","xmqk01075":"","xmqk01076":"","xmqk01077":"","xmqk01078":"","xmqk01079":"","xmqk01080":"","xmqk01081":"","xmqk01082":"","xmqk01083":"","xmqk01084":"","xmqk01085":"","xmqk01086":0,"xmqk01087":"","xmqk01088":"","xmqk01089":"","xmqk01090":"","xmqk01091":"","xmqk01092":"","xmqk01093":"","xmqk01094":"","xmqk01095":"","xmqk01096":"","xmqk01097":"","xmqk01098":"","xmqk01099":0,"xmqk01100":"","xmqk01101":"","xmqk01102":"","xmqk01103":"","xmqk01104":"","xmqk01105":"","xmqk01106":"","xmqk01107":"","xmqk01108":"","xmqk01109":"","xmqk01110":"","xmqk01111":"","xmqk01112":0,"xmqk01113":"","xmqk01114":"","xmqk01115":"","xmqk01116":"","xmqk01117":"","xmqk01118":"","xmqk01119":"","xmqk01120":"","xmqk01121":"","xmqk01122":"","xmqk01123":"","xmqk01124":"","xmqk01125":"","xmqk01126":"","xmqk01127":"","xmqk01128":0,"xmqk01129":0,"xmqk01130":0,"xmqk01131":0,"xmqk01132":"","xmqk01133":0,"xmqk01134":0,"xmqk01135":"","xmqk01136":"","xmqk01137":""},"cjdw":[{"CJDW0101":0,"CJDW0102":0,"CJDW0103":0,"CJDW0104":"单位名称0","CJDW0105":"","CJDW0106":"","CJDW0107":"","CJDW0108":0,"CJDW0109":"","CJDW0110":"","CJDW0111":"","CJDW0112":"","CJDW0113":"","CJDW0114":""}]}
		/*for(int i=0;i<list.size();i++){
			JSONObject obj = list.get(i);
			ZJPF01 zjpf = (ZJPF01)JSONObject.toBean(obj, ZJPF01.class);
			System.out.println(zjpf.getZJPF0101());
		}*/
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		SystemManager sys=new SystemManagerImpl();
		String xmqkStr=request.getParameter("XMQKBASEINFO");//获取项目基本情况和竣工信息
		String cjdwStr=request.getParameter("CJDWLIST");//获取参建单位信息数组
		String zjpfStr=request.getParameter("ZJPFLIST");//获取资金批复信息数组
		String zhdStr = request.getParameter("ZHDLIST");//获取灾害点列表信息数组
		//System.out.println(xmqkStr);
		//System.out.println(zjpfStr);
	//	xmqkStr = "{\"xmqk01001\":1,\"xmqk01002\":\"0000\",\"xmqk01003\":\"测试oneToMany5\",\"xmqk01004\":\"\",\"xmqk01005\":\"\",\"xmqk01006\":\"\",\"xmqk01007\":\"\",\"xmqk01008\":\"\",\"xmqk01009\":\"\",\"xmqk01010\":\"\",\"xmqk01011\":\"\",\"xmqk01012\":\"\",\"xmqk01013\":\"\",\"xmqk01014\":\"\",\"xmqk01015\":\"\",\"xmqk01016\":\"\",\"xmqk01017\":0,\"xmqk01018\":0,\"xmqk01019\":0,\"xmqk01020\":0,\"xmqk01021\":0,\"xmqk01022\":0,\"xmqk01023\":0,\"xmqk01024\":0,\"xmqk01025\":\"\",\"xmqk01026\":\"\",\"xmqk01027\":\"\",\"xmqk01028\":\"\",\"xmqk01029\":\"\",\"xmqk01030\":\"\",\"xmqk01031\":\"\",\"xmqk01032\":\"\",\"xmqk01033\":\"\",\"xmqk01034\":\"\",\"xmqk01035\":\"\",\"xmqk01036\":\"\",\"xmqk01037\":0,\"xmqk01038\":\"\",\"xmqk01039\":\"\",\"xmqk01040\":\"\",\"xmqk01041\":\"\",\"xmqk01042\":\"\",\"xmqk01043\":0,\"xmqk01044\":0,\"xmqk01045\":0,\"xmqk01046\":0,\"xmqk01047\":0,\"xmqk01048\":\"\",\"xmqk01049\":\"\",\"xmqk01050\":\"\",\"xmqk01051\":\"\",\"xmqk01052\":\"\",\"xmqk01053\":\"\",\"xmqk01054\":\"\",\"xmqk01055\":\"\",\"xmqk01056\":\"\",\"xmqk01057\":\"\",\"xmqk01058\":\"\",\"xmqk01059\":\"\",\"xmqk01060\":0,\"xmqk01061\":\"\",\"xmqk01062\":\"\",\"xmqk01063\":\"\",\"xmqk01064\":\"\",\"xmqk01065\":\"\",\"xmqk01066\":\"\",\"xmqk01067\":\"\",\"xmqk01068\":\"\",\"xmqk01069\":\"\",\"xmqk01070\":\"\",\"xmqk01071\":\"\",\"xmqk01072\":\"\",\"xmqk01073\":0,\"xmqk01074\":\"\",\"xmqk01075\":\"\",\"xmqk01076\":\"\",\"xmqk01077\":\"\",\"xmqk01078\":\"\",\"xmqk01079\":\"\",\"xmqk01080\":\"\",\"xmqk01081\":\"\",\"xmqk01082\":\"\",\"xmqk01083\":\"\",\"xmqk01084\":\"\",\"xmqk01085\":\"\",\"xmqk01086\":0,\"xmqk01087\":\"\",\"xmqk01088\":\"\",\"xmqk01089\":\"\",\"xmqk01090\":\"\",\"xmqk01091\":\"\",\"xmqk01092\":\"\",\"xmqk01093\":\"\",\"xmqk01094\":\"\",\"xmqk01095\":\"\",\"xmqk01096\":\"\",\"xmqk01097\":\"\",\"xmqk01098\":\"\",\"xmqk01099\":0,\"xmqk01100\":\"\",\"xmqk01101\":\"\",\"xmqk01102\":\"\",\"xmqk01103\":\"\",\"xmqk01104\":\"\",\"xmqk01105\":\"\",\"xmqk01106\":\"\",\"xmqk01107\":\"\",\"xmqk01108\":\"\",\"xmqk01109\":\"\",\"xmqk01110\":\"\",\"xmqk01111\":\"\",\"xmqk01112\":0,\"xmqk01113\":\"\",\"xmqk01114\":\"\",\"xmqk01115\":\"\",\"xmqk01116\":\"\",\"xmqk01117\":\"\",\"xmqk01118\":\"\",\"xmqk01119\":\"\",\"xmqk01120\":\"\",\"xmqk01121\":\"\",\"xmqk01122\":\"\",\"xmqk01123\":\"\",\"xmqk01124\":\"\",\"xmqk01125\":\"\",\"xmqk01126\":\"\",\"xmqk01127\":\"\",\"xmqk01128\":0,\"xmqk01129\":0,\"xmqk01130\":0,\"xmqk01131\":0,\"xmqk01132\":\"\",\"xmqk01133\":0,\"xmqk01134\":0,\"xmqk01135\":\"\",\"xmqk01136\":\"\",\"xmqk01137\":\"\"}";
		//{"XMQK01018":"","XMQK01127":"","XMQK01010":"","XMQK01017":"","XMQK01002":"","XMQK01126":"","XMQK01118":"","XMQK01128":"","XMQK01119":"","XMQK01004":"","XMQK01129":"","XMQK01137":"市辖区","XMQK01120":"","XMQK01003":"测试录入","XMQK01124":"","XMQK01130":"","XMQK01121":"","XMQK01009":"","XMQK01005":"请选择","XMQK01011":"","XMQK01131":"","XMQK01008":"","XMQK01012":"","XMQK01125":"","XMQK01013":"","XMQK01133":"","XMQK01122":"","XMQK01132":"","XMQK01134":"","XMQK01014":"","XMQK01016":"","XMQK01123":"","XMQK01007":"","XMQK01136":"武汉市","XMQK01006":"","XMQK01135":"","XMQK01015":"","XMQK01019":""}
		//cjdwStr = "[{\"CJDW0101\":0,\"CJDW0102\":0,\"CJDW0103\":114,\"CJDW0104\":\"ccccc\",\"CJDW0105\":\"\",\"CJDW0106\":\"\",\"CJDW0107\":\"\",\"CJDW0108\":0,\"CJDW0109\":\"\",\"CJDW0110\":\"\",\"CJDW0111\":\"\",\"CJDW0112\":\"\",\"CJDW0113\":\"\",\"CJDW0114\":\"\"}]";
	//	zjpfStr = "[{\"ZJPF0101\":0,\"ZJPF0102\":0,\"ZJPF0103\":\"资金批复0\",\"ZJPF0104\":\"\",\"ZJPF0105\":11,\"ZJPF0106\":\"\",\"ZJPF0107\":\"\"},{\"ZJPF0101\":1,\"ZJPF0102\":2,\"ZJPF0103\":\"资金批复1\",\"ZJPF0104\":\"\",\"ZJPF0105\":0,\"ZJPF0106\":\"\",\"ZJPF0107\":\"\"},{\"ZJPF0101\":2,\"ZJPF0102\":4,\"ZJPF0103\":\"资金批复2\",\"ZJPF0104\":\"\",\"ZJPF0105\":0,\"ZJPF0106\":\"\",\"ZJPF0107\":\"\"},{\"ZJPF0101\":3,\"ZJPF0102\":6,\"ZJPF0103\":\"资金批复3\",\"ZJPF0104\":\"\",\"ZJPF0105\":10,\"ZJPF0106\":\"\",\"ZJPF0107\":\"\"}]";

		//{"XMQK01018":"","XMQK01127":"","XMQK01017":"","XMQK01002":"","XMQK01137":"市辖区","XMQK01135":"","XMQK01015":"","XMQK01128":"","XMQK01119":"","XMQK01004":"","XMQK01129":"","XMQK01118":"","XMQK01120":"","XMQK01003":"测试一对多","XMQK01124":"","XMQK01130":"","XMQK01121":"","XMQK01009":"","XMQK01005":"请选择","XMQK01011":"","XMQK01131":"","XMQK01008":"","XMQK01012":"","XMQK01125":"","XMQK01013":"","XMQK01133":"","XMQK01016":"","XMQK01010":"","XMQK01132":"","XMQK01134":"","XMQK01014":"","XMQK01006":"","XMQK01123":"","XMQK01007":"","XMQK01136":"武汉市","XMQK01122":"","XMQK01126":"","XMQK01019":""}
		//[{"ZJPF0103":"B","ZJPF0101":0,"ZJPF0100":null,"ZJPF0107":"","ZJPF0104":"2012","ZJPF0105":"200","ZJPF0102":0,"ZJPF0106":"upload/xm/示例图片_02_1370091873415.jpg"},{"ZJPF0103":"C","ZJPF0101":0,"ZJPF0100":null,"ZJPF0107":"","ZJPF0104":"2011","ZJPF0105":"300","ZJPF0102":0,"ZJPF0106":"upload/xm/示例图片_04_1370091889821.jpg"},{"ZJPF0103":"A","ZJPF0101":0,"ZJPF0100":null,"ZJPF0107":"","ZJPF0104":"2013","ZJPF0105":"100","ZJPF0102":0,"ZJPF0106":"upload/xm/示例图片_03_1370091857087.jpg"}]
		System.out.println(zjpfStr);
		System.out.println(xmqkStr);
		System.out.println(cjdwStr);
		cjdwStr = cjdwStr.replaceAll("null", "\"\"");
		xmqkStr =xmqkStr.replaceAll("null", "\"\"");
		zhdStr = zhdStr.replaceAll("null", "\"\"");
		Xmqk01New xmqk01 = (Xmqk01New)JSONObject.toBean(JSONObject.fromObject(xmqkStr),Xmqk01New.class);//转换成对象
		List<Zjpf01> zjpfList = JsonTools.getDTOList(zjpfStr, Zjpf01.class);//转换成数组
		List<Cjdw01> cjdwList =JsonTools.getDTOList(cjdwStr, Cjdw01.class);//转化成数组
		List<ZHD01> zhdList = JsonTools.getDTOList(zhdStr, ZHD01.class);
		boolean flag=sys.AddXmqk(xmqk01,zjpfList,cjdwList,zhdList);
		out.print(flag);
		out.flush();
		out.close();
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
